package com.ruoyi.tianliangedu.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.tianliangedu.domain.TianliangSubject;
import com.ruoyi.tianliangedu.service.ITianliangSubjectService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 专题增加Controller
 *
 * @author lsj
 * @date 2021-07-12
 */
@Controller
@RequestMapping("/tianliangedu/subject")
public class TianliangSubjectController extends BaseController {
    private String prefix = "tianliangedu/subject";

    @Autowired
    private ITianliangSubjectService tianliangSubjectService;

    @RequiresPermissions("tianliangedu:subject:view")
    @GetMapping()
    public String subject() {
        return prefix + "/subject";
    }

    /**
     * 查询专题增加列表
     */
    @RequiresPermissions("tianliangedu:subject:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TianliangSubject tianliangSubject) {
        startPage();
        List<TianliangSubject> list = tianliangSubjectService.selectTianliangSubjectList(tianliangSubject);
        return getDataTable(list);
    }

    /**
     * 导出专题增加列表
     */
    @RequiresPermissions("tianliangedu:subject:export")
    @Log(title = "专题增加", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TianliangSubject tianliangSubject) {
        List<TianliangSubject> list = tianliangSubjectService.selectTianliangSubjectList(tianliangSubject);
        ExcelUtil<TianliangSubject> util = new ExcelUtil<TianliangSubject>(TianliangSubject.class);
        return util.exportExcel(list, "专题增加数据");
    }

    /**
     * 新增专题增加
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存专题增加
     */
    @RequiresPermissions("tianliangedu:subject:add")
    @Log(title = "专题增加", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TianliangSubject tianliangSubject) {
        return toAjax(tianliangSubjectService.insertTianliangSubject(tianliangSubject));
    }

    /**
     * 修改专题增加
     */
    @GetMapping("/edit/{subId}")
    public String edit(@PathVariable("subId") Integer subId, ModelMap mmap) {
        TianliangSubject tianliangSubject = tianliangSubjectService.selectTianliangSubjectById(subId);
        mmap.put("tianliangSubject", tianliangSubject);
        return prefix + "/edit";
    }

    /**
     * 修改保存专题增加
     */
    @RequiresPermissions("tianliangedu:subject:edit")
    @Log(title = "专题增加", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TianliangSubject tianliangSubject) {
        return toAjax(tianliangSubjectService.updateTianliangSubject(tianliangSubject));
    }

    /**
     * 删除专题增加
     */
    @RequiresPermissions("tianliangedu:subject:remove")
    @Log(title = "专题增加", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(tianliangSubjectService.deleteTianliangSubjectByIds(ids));
    }
}
